package com.hzvtc.bosswang.manageeducation.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzvtc.bosswang.managecommon.domain.AjaxResult;
import com.hzvtc.bosswang.manageeducation.domain.Course;
import com.hzvtc.bosswang.manageeducation.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/edu-manager")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @PostMapping("/add-course")
    private AjaxResult addClass(@RequestBody Course course){
        if (courseService.addCourse(course)>0){
            return new AjaxResult(200,"添加成功",null);
        }
        return new AjaxResult(500,"添加失败",null);
    }

    @PostMapping("/edit-course")
    private AjaxResult editClass(@RequestBody Course course){
        if (courseService.editCourse(course)>0){
            return new AjaxResult(200,"修改成功",null);
        }
        return new AjaxResult(500,"修改失败",null);
    }

    @GetMapping("/view-course/{id}")
    private AjaxResult selectCourseById(@PathVariable Long id){
        Course course = courseService.selectCourseById(id);
        if (course!=null){
            return new AjaxResult(200,"查询成功！",course);
        }
        return new AjaxResult(500,"查询失败",null);
    }

    @PostMapping("/list-course")
    private AjaxResult listCourse(@RequestBody Course course){
        Page<Course> page=new Page<>();
        page.setSize(10);
        page.setCurrent(1);
        return new AjaxResult(200,"查询成功！", courseService.listCourse(page,course));
    }

    @DeleteMapping("/delete-course/{id}")
    private AjaxResult deleteCourse(@PathVariable Long id){
        if (courseService.deleteCourse(id)>0){
            return new AjaxResult(200,"删除成功",null);
        }
        return new AjaxResult(500,"删除失败",null);
    }

}
